package com.lch.distributed.serialize;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * @author: liuchenhui
 * @create: 2019-06-02 21:29
 **/
public class XMLSerializer implements ISerializer {

    static XStream xStream = new XStream(new DomDriver());

    @Override
    public <T> byte[] writeObject(T obj) {
        return xStream.toXML(obj).getBytes();
    }

    @Override
    public <T> T readObject(byte[] data, Class<T> clazz) {
        return (T) xStream.fromXML(new String(data));
    }
}
